<template>
  <div class="wrapper">
    <!-- header部分 -->
    <header>
      <p>编辑送货地址</p>
    </header>
    <!-- 表单部分 -->
    <ul class="form-box">
      <li>
        <div class="content">
          <input type="text" v-model="deliveryAddress.contactName" placeholder="联系人姓名">
        </div>
      </li>
      <li>
        <div class="content">
          <input type="tel" v-model="deliveryAddress.contactTel" placeholder="电话">
        </div>
      </li>
      <li>
        <div class="content">
          <input type="text" v-model="deliveryAddress.address" placeholder="收货地址">
        </div>
      </li>
      <li>
        <div class="content" style="font-size: 3vw;">
          <input type="radio" v-model="deliveryAddress.contactSex" value="1" style="width:6vw;height:3.2vw;" checked>男
          <input type="radio" v-model="deliveryAddress.contactSex" value="0" style="width:6vw;height:3.2vw;">女
        </div>
      </li>
    </ul>
    <div class="button-add">
      <button @click="editUserAddress">更新</button>
    </div>
    <!-- 底部菜单部分 -->
    <Footer></Footer>
  </div>
</template>
<script>
import Footer from '../components/Footer.vue';
export default {
  name: 'EditUserAddress',
  data() {
    return {
      businessId: this.$route.query.businessId,
      daId: this.$route.query.daId,
      user: {},
      deliveryAddress: this.$getLocalStorage(this.$getSessionStorage('user').userId)
    }
  },
  created() {
    this.user = this.$getSessionStorage('user');
  },
  components: {
    Footer
  },
  methods: {
    editUserAddress() {
      // this.deliveryAddress.userId = this.user.userId
      if (this.deliveryAddress.contactName == '') {
        alert('联系人姓名不能为空！');
        return;
      }
      if (this.deliveryAddress.contactTel == '') {
        alert('联系人电话不能为空！');
        return;
      }
      if (this.deliveryAddress.address == '') {
        alert('联系人地址不能为空！');
        return;
      }
      this.$axios.put('deliveryAddresses', this.deliveryAddress, {
        params: {
          token: this.$getSessionStorage("token")
        }
      }
      ).then(response => {
        console.log(response);
        if (response.status === 200) {
          this.$setLocalStorage(this.user.userId, this.deliveryAddress);
          this.$router.push({
            path: '/userAddress',
            query: {
              businessId: this.businessId,
              total: this.$route.query.total ? this.$route.query.total : null
            }
          });
        } else {
          alert('更新地址失败！');
        }
      }).catch(error => {
        console.error(error);
      });
    }
  }
}
</script>
<style scoped>
/*********** 总容器 ***********/
.wrapper {
  width: 100%;
  height: 100%;
}

/*********** header部分 ***********/
.wrapper header {
  width: 100%;
  height: 12vw;
  background-color: #0097ff;
  color: #fff;
  font-size: 4.8vw;

  position: fixed;
  left: 0;
  top: 0;
  /* 提高层次 */
  z-index: 1000;

  display: flex;
  justify-content: space-around;
  align-items: center;
}

/*********** 表单部分 ***********/
.wrapper .form-box {
  width: 100%;
  margin-top: 17vw;
}

.wrapper .form-box li {
  box-sizing: border-box;
  padding: 4vw 3vw 0 3vw;
  margin-top: 2vw;

  display: flex;
  justify-content: center;
  align-items: center;
}



.wrapper .form-box li .content input {
  font-size: 3.5vw;
  padding: 4.5vw 15vw;
  border-radius: 20px;
  border: 0.5px solid #999;
}

.wrapper .button-add {
  display: flex;
  justify-content: center;
  align-items: center;
}

.wrapper .button-add button {
  margin-top: 5vw;
  font-size: 16px;
  padding: 3.5vw 30vw;
  background-color: #0097ff;
  border-radius: 25px;
  border: none;
  color: #fff;
}

.wrapper .button-regist {
  display: flex;
  justify-content: center;
  align-items: center;
}

.wrapper .button-regist button {
  margin-top: 5vw;
  font-size: 16px;
  padding: 3.5vw 28.3vw;
  background-color: #aaa;
  border-radius: 25px;
  border: none;
  color: #444;
}



/*********** 底部菜单部分 ***********/
.wrapper .footer {
  width: 100%;
  height: 14vw;
  border-top: solid 1px #DDD;
  background-color: #fff;
  position: fixed;
  left: 0;
  bottom: 0;

  display: flex;
  justify-content: space-around;
  align-items: center;
}

.wrapper .footer li {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #999;
  user-select: none;
  cursor: pointer;
}

.wrapper .footer li p {
  font-size: 2.8vw;
}

.wrapper .footer li i {
  font-size: 5vw;
}
</style>